<?php

namespace app\home\controller;

use app\common\validate\virtual\VirtualScanTempLogValid;
use app\home\loader\Services;
use think\Exception;

/**
 *  前端扫码,临时记录表
 */
class VirtualScanTempLog extends ApiBase
{
    /**
     * 订单扫码活动商品
     */
    public function list(): void
    {
        $param = input('get.');
        try {
            validate(VirtualScanTempLogValid::class)->scene('virtual_list')->check($param);
            $paramData = [
                'order_no' => $param['order_no'],
                'mer_id' => $this->shopUser['mer_id'],
                'user_id' => $this->shopUser['user_id'],
            ];
            $data = Services::VirtualScanTempLog()->list($paramData);
            api_result(API_SUCCESS, '请求成功', $data);
        } catch (Exception $e) {
            api_result($e);
        }
    }

    /**
     * 订单生成
     */
    public function order_add(): void
    {
        $params = input('post.');
        try {
            validate(VirtualScanTempLogValid::class)->scene('add_order')->check($params);
            $data = [
                'vp_id' => $params['vp_id'],
                'product_code' => $params['product_code'],
                'mer_id' => $this->shopUser['mer_id'],
                'user_id' => $this->shopUser['user_id'],
            ];
            $data = Services::VirtualScanTempLog()->SaveScanLog($data);
            api_result(API_SUCCESS, '请求成功', $data);
        } catch (Exception $e) {
            api_result($e);
        }
    }

    /**
     * 订单追加商品
     */
    public function order_append_product(): void
    {
        $params = input('post.');
        try {
            validate(VirtualScanTempLogValid::class)->scene('append_product')->check($params);
            $data = [
                'product_code' => $params['product_code'],
                'order_no' => $params['order_no'],
                'mer_id' => $this->shopUser['mer_id'],
                'user_id' => $this->shopUser['user_id'],
            ];
            $res = Services::VirtualScanTempLog()->SaveScanLog($data);
            api_result(API_SUCCESS, '请求成功', $res);
        } catch (Exception $e) {
            api_result($e);
        }
    }

}
